package com.sw.small_world.openim;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.View;

import com.alibaba.mobileim.aop.AdviceBinder;
import com.alibaba.mobileim.aop.PointCutEnum;
import com.alibaba.mobileim.aop.Pointcut;
import com.alibaba.mobileim.aop.custom.IMChattingPageOperateion;
import com.alibaba.mobileim.aop.model.ReplyBarItem;
import com.alibaba.mobileim.aop.model.YWChattingPlugin;
import com.alibaba.mobileim.conversation.YWConversation;
import com.alibaba.mobileim.conversation.YWConversationType;
import com.sw.small_world.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/25.
 */

public class ChattingOperationCustom extends IMChattingPageOperateion {
    public ChattingOperationCustom(Pointcut pointcut) {
        super(pointcut);
    }
    /**
     *
     * 用于增加聊天窗口 下方回复栏的操作区的item
     *
     * ReplyBarItem
     * itemId:唯一标识 建议从1开始
     * ItemImageRes：显示的图片
     * ItemLabel：文字
     * needHide:是否隐藏 默认: false ,  显示：false ， 隐藏：true
     * OnClickListener: 自定义点击事件, null则使用默认的点击事件
     * 参照示例返回List<ReplyBarItem>用于操作区显示item列表，可以自定义顺序和添加item
     *
     * @param pointcut         聊天窗口fragment
     * @param conversation 当前会话，通过conversation.getConversationType() 区分个人单聊，与群聊天
     * @param replyBarItemList 默认的replyBarItemList，如拍照、选择照片、短视频等
     * @return
     */
    private static int ITEM_SEE_DELETE = 0X3;
    @Override
    public List<ReplyBarItem> getCustomReplyBarItemList(final Fragment pointcut,
                                                        final YWConversation conversation, List<ReplyBarItem> replyBarItemList) {
        final List<ReplyBarItem> replyBarItems = new ArrayList<ReplyBarItem>();

        for (ReplyBarItem replyBarItem : replyBarItemList) {
            if(replyBarItem.getItemId()== YWChattingPlugin.ReplyBarItem.ID_CAMERA){
                //是否隐藏ReplyBarItem中的拍照选项
                replyBarItem.setNeedHide(false);
                //不自定义ReplyBarItem中的拍照的点击事件,设置OnClicklistener(null);
                replyBarItem.setOnClicklistener(null);
                //自定义ReplyBarItem中的拍照的点击事件,设置OnClicklistener
//                开发者在自己实现拍照逻辑时，可以在{@link #onActivityResult(int, int, Intent, List<YWMessage>)}中处理拍照完成后的操作
//                replyBarItem.setOnClicklistener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//
//                    }
//                });
            }else if(replyBarItem.getItemId()== YWChattingPlugin.ReplyBarItem.ID_ALBUM){
                //是否隐藏ReplyBarItem中的选择照片选项
                replyBarItem.setNeedHide(false);
                //不自定义ReplyBarItem中的相册的点击事件,设置OnClicklistener（null）
                replyBarItem.setOnClicklistener(null);
                //自定义ReplyBarItem中的相册的点击事件,设置OnClicklistener
//                replyBarItem.setOnClicklistener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        IMNotificationUtils.getInstance().showToastLong(pointcut.getActivity(), "用户点击了选择照片");
//                    }
//                });
            }
            replyBarItems.add(replyBarItem);
        }
        if (conversation.getConversationType() == YWConversationType.P2P) {
            final ReplyBarItem replyBarItem3 = new ReplyBarItem();
            replyBarItem3.setItemId(ITEM_SEE_DELETE);
            replyBarItem3.setItemImageRes(R.drawable.demo_reply_bar_private_image);
            replyBarItem3.setItemLabel("阅后即焚");
            replyBarItem3.setOnClicklistener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    AdviceBinder.bindAdvice(PointCutEnum.CHATTING_FRAGMENT_OPERATION_POINTCUT, ChattingOperationCustom1.class);
                }
            });
            replyBarItems.add(replyBarItem3);

        }
        return replyBarItems;
    }
}
